package self.security.entity;

import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import self.security.utils.MD5;

@Component
public class DefaultPasswordEncoder implements PasswordEncoder {
    /**
     * 散列密码的方法
     *
     * @param rawPassword
     * @return
     */
    @Override
    public String encode(CharSequence rawPassword) {
        return MD5.encrypt(rawPassword.toString());
    }

    /**
     * 比较两个密码是否一致的方法
     *
     * @param rawPassword
     * @param encodedPassword
     * @return
     */
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        String encrypt = MD5.encrypt(rawPassword.toString());
        if (encrypt.equals(encodedPassword)) {
            return true;
        }
        return false;
    }

}
